home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / dev / src / spr12.lha / patch1.asm next >
Assembly Source File  |  1995-10-31  |  3KB  |  115 lines

  1.          SECTION  text,CODE
  2.          ;
  3.          ;        Benefits:
  4.          ;        1)  While the patch is in use (and not being removed), there
  5.          ;            is no CPU overhead related to patch removal.  This can
  6.          ;            be significant if the routine is used a lot.  
  7.          ;
  8.          ;        Restrictions:
  9.          ;        1)  The code in between labels "_codeStart" and "_codeEnd"
  10.          ;            MUST NOT call any other routines outside of those labels.
  11.          ;            This limits this method somewhat, but due to the benefits
  12.          ;            should be considered if possible.
  13.          ;
  14.          ;
  15.          ;        Export symbols
  16.          ;
  17.          XDEF     _patchStart
  18.          XDEF     _patchEnd
  19.          XDEF     _codeStart
  20.          XDEF     _codeEnd
  21.          XDEF     _UCount_Offset
  22.          XDEF     _SigBit_Offset
  23.          XDEF     _Task_Offset
  24.          XDEF     _RtsNop_Offset
  25.          ;
  26.          ;        Import symbols
  27.          ;
  28.          XREF     _AbsExecBase
  29.          XREF     _LVODisable
  30.          XREF     _LVOEnable
  31.          XREF     _LVOSignal
  32.          ;
  33.          ;        Here begins the patch.
  34.          ;
  35. _patchStart:
  36.          ;
  37.          ;        Here begins the patch code.
  38.          ;
  39. _codeStart:
  40.          ;
  41.          ;        Do whatever the patch needs to do...
  42.          ;
  43.          move.l   #10,d0
  44.          ;
  45.          ;        When the patch is to be removed, we change the following
  46.          ;        RTS to a NOP instruction.  This way we don't have any
  47.          ;        overhead in the patch.
  48.          ;
  49. RTSNOP   rts
  50.          ;
  51.          ;        Here ends the patch code.
  52.          ;
  53. _codeEnd:
  54.          ;
  55.          ;        Here begins the removal code.
  56.          ;
  57.          ;        Preserve registers.
  58.          ;
  59.          movem.l  d0-d1/a0-a1,-(sp)
  60.          ;
  61.          ;        We decrement the UCOUNT field until it reaches zero.
  62.          ;
  63.          lea.l    UCOUNT(pc),a0
  64.          subq.l   #1,(a0)
  65.          bne.b    10$
  66.          ;
  67.          ;        The UCOUNT field has reached zero so notify remover that it's
  68.          ;        okay to free storage.  Remember that we are still Disabled()
  69.          ;        so the remover can't free our storage yet.
  70.          ;
  71.          move.l   SIGNAL(pc),d0
  72.          move.l   TASK(pc),a1
  73.          move.l   a6,-(sp)
  74.          move.l   _AbsExecBase.W,a6
  75.          jsr      _LVOSignal(a6)
  76.          move.l   (sp)+,a6
  77.          ;
  78.          ;        Restore registers
  79.          ;
  80. 10$      movem.l  (sp)+,d0-d1/a0-a1
  81.          ;
  82.          ;        Return to caller.
  83.          ;
  84.          rts
  85.          ;
  86.          ;        Here ends the removal code.
  87.          ;
  88. _codeEnd:
  89.          ;
  90.          ;        Here begins the removal variables.
  91.          ;
  92. UCOUNT   dc.l     0
  93. SIGNAL   dc.l     0
  94. TASK     dc.l     0
  95.          ;
  96.          ;        Here ends the patch.
  97.          ;
  98. _patchEnd:
  99.          ;
  100.          ;        Here begins some convenience fields.  There are not part of
  101.          ;        the patch.
  102.          ;
  103. _UCount_Offset:
  104.          DC.L     UCOUNT-_patchStart
  105. _SigBit_Offset:
  106.          DC.L     SIGNAL-_patchStart
  107. _Task_Offset:
  108.          DC.L     TASK-_patchStart
  109. _RtsNop_Offset:
  110.          DC.L     RTSNOP-_patchStart
  111.          ;
  112.          ;        The End
  113.          ;
  114.          END
  115.